package org.xlp.base.application.util;

import org.xlp.encryption.EncryptException;
import org.xlp.encryption.MD5HashEncryption;

/**
 * Description: md5加密工具类
 * <br/>date: 2024/12/20 23:53
 *
 * @version 1.0
 * @author: xlp
 */
public class MD5Utils {
    /**
     * MD5加密对象
     */
    private static final MD5HashEncryption MD5 = new MD5HashEncryption();

    /**
     * MD5加密给定的字符串
     *
     * @param source
     * @return
     * @throws NullPointerException 假如参数为null，则抛出该异常
     * @throws RuntimeException 假如加密失败，则抛出该异常
     */
    public static String encode(String source){
        try {
            return MD5.encode(source);
        } catch (EncryptException e) {
            throw new RuntimeException(e);
        }
    }
}
